<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use DB;


class Activity extends Authenticatable
{
    use Notifiable;
	protected $table = 'activity';

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
         'remember_token',
    ];

    // 获取可用的活动
	public static function getActivityId(){
		// 未使用的活动
//		$sql = " SELECT id,activity_name FROM c_activity WHERE id NOT IN(
//				SELECT activity_id FROM c_coupon
//				) and is_del=1 ";

		// 1/2 运营中的活动不可再选择
		$sql = " SELECT id,activity_name from c_activity where id > 2 and is_del=1 ";

		$activityArr = DB::select($sql);
		if(!$activityArr){
			return array();
		}
		return $activityArr;
	}

	// 根据id或者名称
	public static function getNameById($id){
		$name = '';
		$name = Activity::where('id',$id)->pluck('activity_name');
		if($name){
			$name = $name[0];
		}
		return $name;
	}

	// 查询活动下的所有优惠券
	public static function getActivityCoupon($aid){
		$activityCoupons = DB::table('activity')
			->leftjoin('coupon', 'activity.id', '=', 'coupon.activity_id')
			->where('activity.id',$aid)
			->select('coupon.*')
			->get()
			->toArray();
		if(!$activityCoupons){
			return array();
		}
		return $activityCoupons;
	}



}
